package mt;

import java.util.Scanner;

/**
 * @author zhangmin
 * @create 2022-03-26 15:48
 * 7的倍数
 */
public class meituan_0326_3 {
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        int[] nums=new int[n];
        for (int i = 0; i < n; i++) {
            nums[i]= cin.nextInt();
        }
        //dp[i][j]表示前i个数中选择的数和mod7后的余数为j的最大和
        int[][] dp=new int[n+1][7];

        for (int i = 0; i < n+1; i++) {
            for (int j = 0; j < 7; j++) {
                if(i==0){
                   dp[i][j]=0;
                }else {
                    dp[i][j]=Math.max(dp[i-1][j],dp[i-1][(j-(nums[i-1]%7)+7)%7]+nums[i-1]);
                }
            }
        }
        System.out.println(dp[n][0]);
    }
}
